package main

import (
	"bytes"
	"fmt"
	log "github.com/sirupsen/logrus"
	"io"
	"os"
	"time"
)

func main() {
	log.Errorln("")
	b := bytes.Buffer{}
	writer1 := &b
	//writer2 := os.Stdout
	writer3, err := os.OpenFile("log.txt", os.O_WRONLY|os.O_CREATE, 0755)
	if err != nil {
		log.Fatalf("create file log.txt failed: %v", err)
	}
	logSub := log.New()

	logSub.SetOutput(io.MultiWriter(writer1, writer3))
	go func(logMine *log.Logger) {
		for i := 0; i < 1000; i++ {
			logMine.Println("Sub", i)
			time.Sleep(time.Second * 1)
		}
	}(logSub)
	go func() {
		for i := 0; i < 1000; i++ {
			//fmt.Println(b.String())
			line, err := b.ReadString('\n')
			fmt.Println(i, line, err)
			time.Sleep(time.Second * 1)
		}
	}()
	select {}
}
